# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=pax-utils
pkgver=1.3.8
pkgrel=1
pkgdesc="ELF related utils for ELF 32/64 binaries"
url="https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities"
arch="all"
license="GPL-2.0-only"
depends="scanelf"
makedepends_build="meson"
makedepends_host="linux-headers libcap-dev"
checkdepends="bash python3 py3-elftools"
subpackages="$pkgname-doc scanelf:_scanelf lddtreepax:_lddtreepax:noarch"
[ -n "$BOOTSTRAP" ] && options="$options !check" # prevent python dependency
source="https://dev.gentoo.org/~sam/distfiles/app-misc/pax-utils/pax-utils-$pkgver.tar.xz"

build() {
	if [ -z "$BOOTSTRAP" ]; then
		local lto="-Db_lto=true"
	fi
	abuild-meson \
		$lto \
		-Dlddtree_implementation=sh \
		-Duse_seccomp=false \
		-Duse_libcap=enabled \
		. output
	meson compile -C output
}

check() {
	meson test --print-errorlogs --no-rebuild -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# Don't conflict with main/lddtree
	mv "$pkgdir"/usr/bin/lddtree "$pkgdir"/usr/bin/lddtreepax
}

_scanelf() {
	depends=""
	pkgdesc="Scan ELF binaries for stuff"
	replaces="pax-utils"

	amove usr/bin/scanelf
}

_lddtreepax() {
	depends="python3 py3-elftools"
	pkgdesc="Read and package ELF dependency trees"

	amove usr/bin/lddtreepax
}

sha512sums="
0dde95f86802729d80b7b38af84dec636e973f6abc70600633edcb05d3d5f95c1b2861300ce478dd7f798c7a1e5eccb1011c06c53adba38e11a996b69d463656  pax-utils-1.3.8.tar.xz
"
